home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / examples / poly.c < prev    next >
C/C++ Source or Header  |  1997-10-09  |  2KB  |  134 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include "gl.h"
  5. #include "device.h"
  6. #include "hershey.h"
  7. #else
  8. #include "vogl.h"
  9. #include "vodevice.h"
  10. #endif
  11.  
  12. /*
  13.  *    An array of points for a polygon
  14.  */
  15. static Coord    parray[][3] = {
  16.     {-8.0, -8.0, 0.0},
  17.     {-5.0, -8.0, 0.0},
  18.     {-5.0, -5.0, 0.0},
  19.     {-8.0, -5.0, 0.0}
  20. };
  21.  
  22. /*
  23.  * drawpoly
  24.  *
  25.  *    draw some polygons
  26.  */
  27. void drawpoly(void)
  28. {
  29.     float    vec[3];
  30.     short    val;
  31.  
  32.     color(YELLOW);
  33.  
  34.     /*
  35.      * Draw a polygon using poly, parray is our array of
  36.      * points and 4 is the number of points in it.
  37.      */
  38.     poly(4L, parray);
  39.  
  40.     color(GREEN);
  41.  
  42.     /*
  43.      * Draw a 5 sided figure by using bgnpolygon, v3d, and endpolygon
  44.      */
  45.     polymode(PYM_LINE);
  46.     bgnpolygon();
  47.         vec[0] = 0.0;
  48.         vec[1] = 0.0;
  49.         vec[2] = 0.0;
  50.         v3f(vec);
  51.         vec[0] = 3.0;
  52.         vec[1] = 0.0;
  53.         vec[2] = 0.0;
  54.         v3f(vec);
  55.         vec[0] = 3.0;
  56.         vec[1] = 4.0;
  57.         vec[2] = 0.0;
  58.         v3f(vec);
  59.         vec[0] = -1.0;
  60.         vec[1] = 5.0;
  61.         vec[2] = 0.0;
  62.         v3f(vec);
  63.         vec[0] = -2.0;
  64.         vec[1] = 2.0;
  65.         vec[2] = 0.0;
  66.         v3f(vec);
  67.     endpolygon();
  68.  
  69.     color(MAGENTA);
  70.  
  71.     /*
  72.      * draw a sector representing a 1/4 circle
  73.      */
  74.     arc(1.5, -7.0, 3.0, 0, 900);
  75.  
  76.     move2(1.5, -7.0);
  77.     draw2(1.5, -4.0);
  78.  
  79.     move2(1.5, -7.0);
  80.     draw2(4.5, -7.0);
  81.  
  82.     qread(&val);
  83. }
  84.  
  85. /*
  86.  * drawpolyf
  87.  *
  88.  *    draw some filled polygons
  89.  */
  90. void drawcircle(void)
  91. {
  92.     color(YELLOW);
  93.     circ(1.5,-7.0,2.0);
  94.     // swapbuffers();
  95. }
  96.  
  97. /*
  98.  * Using polygons, hatching, and filling.
  99.  */
  100. int main(void)
  101. {
  102.     int    i;
  103.  
  104.  
  105.     winopen("poly");
  106.  
  107.     unqdevice(INPUTCHANGE);
  108.     qdevice(KEYBD);        /* enable keyboard */
  109.  
  110.     // doublebuffer();
  111.  
  112.     color(BLACK);        /* clear to black */
  113.     clear();
  114.  
  115.     /*
  116.      * world coordinates are now in the range -10 to 10
  117.      * in x, y, and z. Note that positive z is towards us.
  118.      */
  119.     ortho(-10.0, 10.0, -10.0, 10.0, 10.0, -10.0);
  120.  
  121.     color(YELLOW);
  122.  
  123.     drawcircle();
  124.         
  125.     for(i=16;i<40;i++)
  126.     {
  127.         rot((float)(i/2), 'x');
  128.         rot((float)(i/2)+6.0, 'z');
  129.         rot((float)(i/5), 'y');
  130.     }
  131.     
  132.     gexit();
  133. }
  134.